﻿@using KRM.Core
@model IEnumerable<tblProductSubOption>
@{
    var db = new KRMEntities();
    int priceid = ViewBag.priceid;
    var productprice = db.vCurrentProductAlias.FirstOrDefault(a => a.ID == priceid) ?? new vCurrentProductAlia();
    var tradeSubOptionList = productprice.TradeCustomersSubOptions();
}

<div id="pnSubOptions" style="height: 130px">
    @foreach (var item in Model)
    {
        var subOptionItems = new List<tblProductSubOptionItem>
        {
            new tblProductSubOptionItem()
            {
                ProductSubOptionItemText = "Not Required", 
                ProductSubOptionItemPrice = 0
            }
        };
        subOptionItems.AddRange(db.tblProductSubOptionItems.Where(a => a.ProductSubOptionID == item.ProductSubOptionID));
        <div class="row-fluid">
            <div class="span5">
                @item.ProductSubOptionName
            </div>
            <div class="span7">
                <select class="input-block-level" onchange="neworderproductsuboptionchange()" name="productSubOptionItemId">
                    @foreach (var subOptionitem in subOptionItems)
                    {
                        <option value="@(subOptionitem.ProductSubOptionItemID)_@subOptionitem.ProductSubOptionItemPrice"
                            @(tradeSubOptionList.FirstOrDefault(a => a.SubOptionItemID == subOptionitem.ProductSubOptionItemID) != null ? "selected=selected" : "")>
                            @subOptionitem.ProductSubOptionItemText (£@subOptionitem.ProductSubOptionItemPrice.ToString("N2"))
                        </option>
                    }
                </select>
            </div>
        </div>
    }
</div>
<input type="hidden" id="hfcurrentPrice" value="@ViewBag.Price"/>
<input type="hidden" name="priceid" value="@priceid"/>
<div class="row-fluid">
    <div class="span3">
        <input type="text" class="input-block-level" id="currentprice" value="£@ViewBag.Price.ToString("N2")" readonly="readonly" name="price"/>
    </div>
    <div class="span2 text-right">Trade Code</div>
    <div class="span7">
        <input type="text" class="input-block-level" name="tradecode" value="@productprice.ProductCode" />
    </div>
</div>
<div class="row-fluid">
    <div class="span2">Trade Price (£)</div>
    <div class="span3">
        <input type="text" class="input-block-level" value="@(productprice.TradeOptionPrice > 0 ? productprice.TradeOptionPrice.ToString("N2") : "0.00")" name="tradeprice" />
    </div>
    <div class="span2 text-right">
        Trade Barcode
    </div>
    <div class="span3">
        <input type="text" class="input-block-level" value="@productprice.TradeBarcode" name="tradebarcode" />
    </div>
    <div class="span2">
        <input type="submit" class="btn btn-primary" value="@(priceid > 0 ? "Update" : "Create")" style="width: 100%" />
    </div>
</div>
